/*
 * Scripts for sign in page
 */

/*
 * Send a sign in request to the server
 */
function sendSignInRequest(event) {
	var name = document.getElementById('username').value;
	var gameid = document.getElementById('gameid').value;
	var request = {name : name, game : gameid};
	alert('About to send: ' + JSON.stringify(request));
	$.ajax({
	  type: 'POST',
	  url: '/signin',
	  data: request,
	  success: responseHandler,
	  dataType: 'json'
	});
}

/*
 * Receive a response to the sign in request
 */
function handleSignInResponse(response) {	
	var dlResponse = response.response;
	window.clientId = dlResponse.id;
	window.numChoices = dlResponse.signInResponse.numChoices;
	window.numRounds = dlResponse.signInResponse.numRounds;
	window.playerPosition = dlResponse.signInResponse.position;
	window.choices = dlResponse.signInResponse.choice;
	sessionStorage['eventType'] = dlResponse.signInResponse.type;
	
	if (sessionStorage['eventType'] == "closed") {
		displayAddEdgeForm();
	}
	else {
		displayAddChoiceForm();
		addToolTipListeners();
	}
}
